local qieshou = fk.CreateSkill {
  name = "xiaobai__qieshou"
}

Fk:loadTranslationTable {
  ["xiaobai__qieshou"] = "且守",
  [":xiaobai__qieshou"] = "你可以将一张装备牌作为【闪】使用或打出，若此做，你可以令一名其他角色获得此牌，然后若其没有“且佃”，你可以失去此技能并令其获得“且佃”。",
  ["#xiaobai__qieshou"] = "且守：你可以将一张装备牌作为【闪】使用或打出",
  ["#xiaobai__qieshou_give"] = "且守：你可以令一名其他角色获得%arg",
  ["#xiaobai__qieshou_giveSkill"] = "且守：你可以失去“且守”并令 %dest 获得“且佃”",

  ["$xiaobai__qieshou1"] = "兵者，农之锋镝；农者，兵之根柢。",
  ["$xiaobai__qieshou2"] = "倡守边劝农、立耕战赏罚，使海滨晏然！"
}

qieshou:addEffect("viewas", {
  anim_type = "defensive",
  pattern = "jink",
  prompt = "#xiaobai__qieshou",
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return nil end
    local card = Fk:cloneCard("jink")
    card:addSubcard(cards[1])
    card.skillName = qieshou.name
    return card
  end,
  after_use = function (self, player, use)
    local room = player.room
    local geter = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player),
      skill_name = qieshou.name,
      prompt = "#xiaobai__qieshou_give:::"..Fk:getCardById(use.card.subcards[1]):toLogString(),
      cancelable = true,
    })
    if #geter == 0 then return end
    local to = geter[1]
    room:obtainCard(to, use.card.subcards, false, fk.ReasonPrey, player, qieshou.name)
    if player.dead or to.dead or to:hasSkill("xiaobai__qietian", true, true) and player:hasSkill(qieshou.name) then return end

    if not room:askToSkillInvoke(player, {
      skill_name = qieshou.name,
      prompt = "#xiaobai__qieshou_giveSkill::"..to.id
    }) then return end

    room:handleAddLoseSkills(player, "-xiaobai__qieshou")
    room:handleAddLoseSkills(to, "xiaobai__qietian")
  end,
})

return qieshou